package com.company.calendar.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.calendar.entity.Company;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 公司Mapper接口
 * 
 * @author System
 * @since 1.0.0
 */
@Mapper
public interface CompanyMapper extends BaseMapper<Company> {
    
    /**
     * 根据公司编码查找公司
     */
    @Select("SELECT * FROM companies WHERE company_code = #{companyCode} AND is_deleted = 0")
    Company findByCompanyCodeAndIsDeletedFalse(@Param("companyCode") String companyCode);
    
    /**
     * 查找所有未删除的公司
     */
    @Select("SELECT * FROM companies WHERE is_deleted = 0")
    List<Company> findByIsDeletedFalse();
    
    /**
     * 根据公司名称模糊查询
     */
    @Select("SELECT * FROM companies WHERE company_name LIKE CONCAT('%', #{companyName}, '%') AND is_deleted = 0")
    List<Company> findByCompanyNameContaining(@Param("companyName") String companyName);
    
    /**
     * 检查公司编码是否存在
     */
    @Select("SELECT COUNT(*) FROM companies WHERE company_code = #{companyCode} AND is_deleted = 0")
    int existsByCompanyCodeAndIsDeletedFalse(@Param("companyCode") String companyCode);
}
